/**
 * https://leetcode-cn.com/problems/intersection-of-two-arrays/
 * 求两个数组的交集
 * @param nums1 
 * @param nums2 
 */
const intersection = (nums1: number[], nums2: number[]): number[] => {
    const iSet = new Set<number>()

    // 存储它们的答案
    const set = new Set<number>()

    // 存储nums1的数据
    for (let n1 of nums1) {
        iSet.add(n1)
    }

    for (let n2 of nums2) {
        if (iSet.has(n2)) set.add(n2)
    }

    return [...set]
};


const intersection2 = (nums1: number[], nums2: number[]): number[] => {
    const map: Record<number, boolean> = {}

    // 存储它们的答案
    const set = new Set<number>()

    // 存储nums1的数据
    for (let n1 of nums1) {
        map[n1] = true
    }

    for (let n2 of nums2) {
        if (map[n2]) set.add(n2)
    }

    return [...set]
};